module Menu where 

import Addressbook

main (DB c g) = do menuLoop (DB c g)

-- ---- GŁÓWNA PĘTLA PROGRAMU ----------------------------------
menuLoop (DB c g) = do putStrLn "=============================================================="
                       putStrLn "======= Ksiazka adresowa = Menu glowne ======================="
                       putStrLn "=============================================================="
                       putStrLn "1  Zarzadzanie kontaktami"
                       putStrLn "2  Zarzadzanie grupami"
                       putStrLn "3  Wyszukiwanie"
                       putStrLn "4  Kto ma dzisiaj urodziny"
                       putStrLn "0  Wyjscie"
                          
                       cmd <- getLine
                         
                       case cmd of "1" -> do manageContacts (DB c g)
                                   "2" -> do manageGroups   (DB c g)
                                   "3" -> do find           (DB c g)
                                   "4" -> do whereIsParty   (DB c g)
                                   "0" -> do putStrLn       "Koniec."
                                   otherwise -> do putStrLn "Nieprawidlowy nr opcji"
                                                   menuLoop (DB c g)

-- ---- ZARZADZANIE KONTAKTAMI ---------------------------------
manageContacts (DB c g) = do putStrLn "=============================================================="
                             putStrLn "======= Ksiazka adresowa = Zarzadzanie kontaktami ============"
                             putStrLn "=============================================================="
                             putStrLn "1  Wyswietl kontakty"
                             putStrLn "2  Dodaj kontakt"
                             putStrLn "3  Edytuj kontakt"
                             putStrLn "4  Usun kontakt"
                             putStrLn "0  Wroc"
         
                             cmd <- getLine
         
                             case cmd of "1" -> do menuShowContacts     (DB c g)
                                         "2" -> do menuInsertContact    (DB c g)
                                         "3" -> do menuUpdateContact    (DB c g) 
                                         "4" -> do menuDeleteContact    (DB c g)
                                         "0" -> do menuLoop             (DB c g)
                                         otherwise -> do putStrLn       "Nieprawidlowy nr opcji"
                                                         manageContacts (DB c g)

-- ---- ZARZADZANIE GRUPAMI ------------------------------------
manageGroups (DB c g) = do putStrLn "=============================================================="
                           putStrLn "======= Ksiazka adresowa = Zarzadzanie grupami ==============="
                           putStrLn "=============================================================="
                           putStrLn "1  Wyswietl grupy"
                           putStrLn "2  Dodaj grupe"
                           putStrLn "3  Edytuj nazwe grrupy"
                           putStrLn "4  Scal grupy"
                           putStrLn "5  Zarzadzaj czlonkami grupy"
                           putStrLn "6  Usuń grupe"
                           putStrLn "0  Wroc"
         
                           cmd <- getLine
         
                           case cmd of "1" -> do menuShowGroups     (DB c g)
                                       "2" -> do menuAddGroups      (DB c g)
                                       "3" -> do menuUpdateGroups   (DB c g)
                                       "4" -> do menuSumGroups      (DB c g)
                                       "5" -> do menuManageMembers  (DB c g)
                                       "6" -> do menuDeleteGroups   (DB c g)
                                       "0" -> do menuLoop           (DB c g)
                                       otherwise -> do putStrLn     "Nieprawidlowy nr opcji"
                                                       manageGroups (DB c g)
        
-- ---- SZUKAJKI -----------------------------------------------
find (DB c g) = do putStrLn "=============================================================="
                   putStrLn "======= Ksiazka adresowa = Szukajki =========================="
                   putStrLn "=============================================================="
                   putStrLn "1  Znajdź kontakt po ..."
                   putStrLn "2  Znajdź czlonkow grupy"
                   putStrLn "0  Wroc"
         
                   cmd <- getLine
         
                   case cmd of "1" -> do findContact          (DB c g)
                               "2" -> do findMembers          (DB c g)
                               "0" -> do menuLoop             (DB c g)
                               otherwise -> do putStrLn       "Nieprawidlowy nr opcji"
                                               manageContacts (DB c g)

-- KONTAKTY

menuShowContacts (DB c g) = do putStrLn ( contactsToString c )
                               manageContacts (DB c g)
 
menuInsertContact (DB c g) = do putStrLn "====================================="
                                putStr "Podaj imie: "
                                name <- getLine
                                putStr "Podaj nazwisko: "
                                -- surname <- getLine

menuUpdateContact (DB c g) = do putStrLn "====================================="
                                putStr "Podaj id kontaktu: "
                                -- id <- getLine
                                 
menuDeleteContact (DB c g) = do putStrLn "====================================="
                                putStr "Podaj id kontaktu: "
                                id <- getLine
                                let id = 0
                                manageContacts ( DB ( deleteContact c id ) g )        

-- GRUPY
                                 
menuShowGroups (DB c g) = do putStrLn "====================================="
                             manageGroups ( DB c g )  

menuAddGroups (DB c g) = do putStrLn "====================================="
                            manageGroups ( DB c g )
                             
menuUpdateGroups (DB c g) = do putStrLn "====================================="
                               manageGroups ( DB c g )
                             
menuSumGroups (DB c g) = do putStrLn "====================================="
                            manageGroups ( DB c g )
                             
menuManageMembers (DB c g) = do putStrLn "====================================="
                                manageGroups ( DB c g )
                             
menuDeleteGroups (DB c g) = do putStrLn "====================================="
                               manageGroups ( DB c g )

-- SZUKAJKI
                             
findContact (DB c g) = do putStrLn "====================================="
                          find ( DB c g )
                             
findMembers (DB c g) = do putStrLn "====================================="
                          find ( DB c g )
                             
-- KTO MA DZISIAJ URODZINY

whereIsParty (DB c g) = error "w DUPENCJE!"
                                                         
                                                 